//
//  JYOrderCollectionView.m
//  JYFarm
//
//  Created by 花花 on 2017/10/16.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYOrderCollectionView.h"
#import "JYOrderCollectionViewCell.h"

@interface JYOrderCollectionView()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property (nonatomic, weak) UICollectionView *collectionView;
@end
@implementation JYOrderCollectionView
//- (instancetype)initWithFrame:(CGRect)frame{
//
//    if (self == [super initWithFrame:frame]) {
//    
//        
//    }
//    return self;
//}

-(void)setOrderDataArr:(NSArray *)orderDataArr{

    _orderDataArr = orderDataArr;
    [self.collectionView reloadData];

}
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        
        //1.初始化layout
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        
        //  设置collectionview的滚动方向
        [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        
        //  设置headerView的尺寸
        //        layout.headerReferenceSize = CGSizeMake(self.frame.size.width, 100);
        
        //2.初始化collectionView
        UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout: layout];
        
        collectionView.backgroundColor = [UIColor whiteColor];
        collectionView.showsHorizontalScrollIndicator = NO;
        
        
        [collectionView registerNib:[UINib nibWithNibName:@"JYOrderCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"JYOrderCollectionViewCell"];
        
        collectionView.delegate = self;
        collectionView.dataSource = self;
        
        [self addSubview:collectionView];
        _collectionView = collectionView;
    }
    return _collectionView;
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
   
    return self.orderDataArr.count;
}

//设置collectionView 的Cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    
    // 普通的Cell
    JYOrderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"JYOrderCollectionViewCell" forIndexPath:indexPath];
    cell.imgView.image = [UIImage imageNamed:@"home_icon_wine"];
//    cell.rightDownDetailModel = rightDownDetailModel;
    
    return cell;
    
}


//Cell选中
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    NSLog(@"%zd",indexPath.row);
}


//每个item的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

    return CGSizeMake(80, 80);
}

//设置每个item的UIEdgeInsets
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 10, 0, 10);
}

//设置每个item的水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    if (section == 1) {
        return 1;
    }
    return 5;
}

//设置每个item垂直间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    if (section == 1) {
        return 1;
    }
    return 5;
}



@end
